#!/bin/sh

cd /root/code/flask

folder="/root/code/flask/venv"

if [ ! -d "$folder" ]; then
    virtualenv venv
    source venv/bin/activate

    pip install flask
    pip install gunicorn
    pip install flask-bootstrap
    pip install pymongo
    pip install flask-moment
fi

source /root/code/flask/venv/bin/activate

/root/code/flask/venv/bin/gunicorn setup:app &

filename=/root/code/flask/setup.py
inotifywait -mrq --event modify  $filename | while read line
do
    kill -9 $(ps aux | grep gunicorn | grep -v 'grep'| awk '{print $2}')
    cd /root/code/flask && /root/code/flask/venv/bin/gunicorn setup:app &
done